#pragma once

#include <iostream>
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator(){}
    ~Calculator(){}
    Response Exec(Request &req)
    {
        Response resp;
        // 计算处理
        // 在Response --> Set接口， Request  --> Get接口
        // 判断运算符号是什么
        switch (req.Oper())
        {
            case '+':
            {
                resp.SetResult(req.X() + req.Y());
                break;
            }
            case '-':
            {
                resp.SetResult(req.X()-req.Y());
                break;
            }
            case '*':
            {
                resp.SetResult(req.X()*req.Y());
                break;
            }
            case '/':
            {
                if(req.Y()==0)
                {
                    resp.SetCode(1);
                }
                else{
                    resp.SetResult(req.X()/req.Y());
                }
                break;
            }
            case '%':
            {
                if(req.Y()==0)
                {
                    resp.SetCode(2);
                }
                else{
                    resp.SetResult(req.X()%req.Y());
                }
                break;
            }
            default :
                resp.SetCode(3);
                break;
        }
        return resp;
    }
};